const { Octokit } = require("@octokit/core");

const octokit = new Octokit({ auth: `77e86c0508ff32ab08e6b988f337e23fde3cc3c7` });

const config = {
	owner: 'followgiant',
	repo: 'followgiant.github.io'
}

async function getIssues() {
	const res = await octokit.request('GET /repos/{owner}/{repo}/issues', {
	  owner: config.owner,
	  repo: config.repo,
	  per_page: 100
	})

	return res;
}

async function getCommentsByIssue(issueNumber) {
	const res = await octokit.request('GET /repos/{owner}/{repo}/issues/{issue_number}/comments', {
	  owner: config.owner,
	  repo: config.repo,
	  issue_number: issueNumber
	})

	return res;
}

async function renderMarkdown(text) {
	const res = await octokit.request('POST /markdown', {
	  text: text
	})

	return res;
}

module.exports = {
	getIssues,
	getCommentsByIssue,
	renderMarkdown
}